package ccnu.agile.enums;

import ccnu.agile.constant.System;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Description: 对外错误码枚举
 * @Author: JreamY
 * @Create: 2021/10/22
 */
public enum PubError {

    /**
     * 全局：系统异常
     */
    RUNTIME_EXCEPTION(BusinessModel.GLOBAL, "00", "系统异常"),
    /**
     * 全局：用户未登录
     */
    USER_NOT_LOGIN(BusinessModel.GLOBAL, "01", "请先登录"),
    /**
     * 公共访问资源：token失效
     */
    FILE_UPLOAD_TOKEN_EXPIRE(BusinessModel.ANONYMOUS, "00", "token失效"),
    /**
     * 公共访问资源：token无效
     */
    FILE_UPLOAD_INVALID_TOKEN(BusinessModel.ANONYMOUS, "01", "token无效"),

    ;

    private BusinessModel model;

    private String code;

    private String errorDesc;

    PubError(BusinessModel model, String code, String errorDesc) {
        this.model = model;
        this.code = code;
        this.errorDesc = errorDesc;
    }

    private String errorCode;

    public String getErrorDesc() {
        return this.errorDesc;
    }

    public String getErrorCode() {

        StringBuilder errorCode = new StringBuilder(System.Error.PREFIX);
        errorCode.append(model.getCode()).append(System.Error.OUTSIDE).append(code);
        return errorCode.toString();
    }
}
